/**
 * Copyright (C), 2016, 上海赛可电子商务有限公司
 * Author:   李加良
 * Date:     2016-5-11
 * Description: 详情页评论咨询交互事件
 */

/**注销登录*/
function userSsoLogout(){
	$.ajax({
		url:getRootPath()+'simple/logout.htm',
		type:'post',
		dataType:'json',
		success:function(data){
			if(data){
				window.location.reload(true);
			}else{
				alert("注销失败");
				window.location.reload(true);
			}
		}
	});
};
/**注销登录*/
function getStockInfo(){
	$.ajax({
		url:'/product/getStock.htm?spuId=' + spuId,
		type:'post',
		dataType:'json',
		success:function(data){
			if(data){
				alert(data.totalAvailableNum);
			}else{
				alert("注销失败");
			}
		}
	});
}
;(function($){
	
	var commentNode = $('#evaluation_content'),
		buyNode = $(".buy-ask-area"),
		doc = $('html, body');
	
	detailCommentPage = {
		init : function(){
			//切换咨询tab
			this.turnConsultationPage();
			
			//发表咨询 按钮
			this.btnPublishAsk();
		},
		//分页
		goPage: function(currentPageNo){
			$.ajax({
				url:"/product/evaluation.htm",
				type:'POST',
				data:{
					currentPage:currentPageNo,
					spuId:spuId,
					channelId:channelId,
					modelShow:modelShow
				},
				success:function(response){
					$('#evaluation_content').html(response);
					commentList.figCation('#evaluation_content');
					
					var goTop = commentNode.offset().top;
					
					doc.stop().animate({
						'scrollTop': goTop-41
					}, 10 , 'swing');
					
				},
				error:function(errorMessage){

				}
			});
		},
		//咨询分页
		goConsultationPage: function(currentPageNo){
			var subObjectType = $(".buy-ask-list a.selected").attr("subType");
			if(subObjectType==undefined||subObjectType==null){
				subObjectType=0;
			}
			$.ajax({
				url:"/product/consultation.htm",
				type:'POST',
				data:{
					currentPage:currentPageNo,
					spuId:spuId,
					channelId:channelId,
					subObjectType:parseInt(subObjectType),
					modelShow:modelShow
				},
				success:function(response){
					$('#consultation_content').html(response);
					commentList.figCation('#consultation_content');
					
					var goTop = buyNode.offset().top;
					doc.stop().animate({
						'scrollTop': goTop-41
					}, 10 , 'swing');
					
				},
				error:function(errorMessage){

				}
			});
		},
		//咨询tab切换 author by 李加良
		turnConsultationPage: function(){
			$(document).on("click",".subTypeEvent",function(){
				if(!$(this).hasClass("selected")){
					$(this).siblings().removeClass("selected");
					$(this).addClass("selected");
					//初始化tab分页
					detailCommentPage.goConsultationPage(1);
				}
			});
		},
		btnPublishAsk: function(){
			var publishAsk = $('#publishAsk'),
				win = $(window),
				doc = $('html, body');
			$('.btn-publish-ask').on('click',function(){
				var goTop = publishAsk.offset().top;

				doc.stop().animate({

					'scrollTop': goTop-40

				},1000, 'swing');
				
			});
		}
	};
	detailCommentPage.init();
})(jQuery,window);